package ${serviceImplPackage};

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ${entityPackage}.${domainObjectName};
import ${entityPackage}.${domainObjectName}Key;
import ${entityPackage}.${domainObjectName}Example;
import ${mappingPackage}.${domainObjectName}Mapper;
import ${pagingInfo}.PagingInfo;
import ${servicePackage}.${domainObjectName}Service;
import com.github.pagehelper.PageHelper;

@Service
public class ${domainObjectName}ServiceImpl implements ${domainObjectName}Service {
    @Autowired
    ${domainObjectName}Mapper ${lowerDomainObjectName}Mapper;

	@Override
	public ${domainObjectName} selectByPrimaryKey(${domainObjectName}Key id) {
		return ${lowerDomainObjectName}Mapper.selectByPrimaryKey(id);
	}
	
    @Override
    public List<${domainObjectName}> pagingList(PagingInfo pagingInfo) {
    	
        PageHelper.startPage(pagingInfo.getPageNum(),pagingInfo.getPageSize());
        
        ${domainObjectName}Example ${lowerDomainObjectName}Example = new ${domainObjectName}Example();
        pagingInfo.buildExample(${lowerDomainObjectName}Example,${domainObjectName}.class);
        List<${domainObjectName}> ${lowerDomainObjectName}List = ${lowerDomainObjectName}Mapper.selectByExample(${lowerDomainObjectName}Example);
        return ${lowerDomainObjectName}List;
    }

	@Override
	public List<${domainObjectName}> list() {
		return ${lowerDomainObjectName}Mapper.selectByExample(null);
	}

	@Override
	public void saveOrUpdate(${domainObjectName} ${lowerDomainObjectName}) {
		${domainObjectName} ${lowerDomainObjectName}Tmp = ${lowerDomainObjectName}Mapper.selectByPrimaryKey(${lowerDomainObjectName});
		if(${lowerDomainObjectName}Tmp == null) {
			${lowerDomainObjectName}Mapper.insert(${lowerDomainObjectName});
		}else {
			${lowerDomainObjectName}Mapper.updateByPrimaryKeySelective(${lowerDomainObjectName});
		}
	}

	@Override
	public void delete(List<${domainObjectName}Key> ids) {
        ids.forEach(id -> {
            ${lowerDomainObjectName}Mapper.selectByPrimaryKey(id);
        });
	}
}
